import org.w3c.dom.Node;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:${USER}
 * Date:${YEAR}-${MONTH}-${DAY}
 * ${TIME}
 */
import java.util.Scanner;

public class Main {
    class Node {
        public int val;
        public List<Node> children;

        public Node() {}

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    };


    public List<List<Integer>> levelOrder(Node root) {
        if(root==null){
            return new  LinkedList<>();
        }
        Queue<Node> queue=new LinkedList<>();
        List<List<Integer>> lists=new ArrayList<>();
        queue.add(root);

        while (!queue.isEmpty()) {
            List<Integer> ret = new ArrayList<>();
            int sz = queue.size();
            for (int i = 0; i < sz; i++) {
                Node node = queue.poll();
                ret.add(node.val);
                for (Node child : node.children) {
                    if (child != null) {
                        queue.add(child);
                    }
                }
            }
            lists.add(ret);
        }
        return lists;
    }
}